package com.homson.coreservice.serviceapp.user;

import com.homson.coreservice.serviceapi.action.UserActionApi;
import com.homson.coreservice.servicecommon.expection.SystemException;
import com.homson.coreservice.servicecommon.request.RequestParameter;
import com.homson.coreservice.servicecommon.co.UserCreateCO;
import com.homson.coreservice.servicecommon.response.BaseResponse;
import com.homson.servicedomain.domain.user.UserCreateCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import static com.homson.coreservice.servicecommon.enumeration.ResponseCodeEnum.*;
import static com.homson.coreservice.servicecommon.enumeration.ResponseCodeEnum.INTERNAL_SERVER_ERROR;


/**
 * @author: homson_leo
 * @contact: hey_超级巨星（Homson_Leo）- 刘泓岑 1196816884@qq.com
 * @time: 2025/10/4 12:59 PM
 **/
@Service
public class UserActionService implements UserActionApi {
    
    @Autowired
    private UserCreateCommand userCreateCommand;
    
    @Override
    public BaseResponse registerOrUpdateUser(RequestParameter<UserCreateCO> request) {
        try {
            UserCreateCO params = request.getBody();
            userCreateCommand.registerOrUpdate(params.getUserId(), params);
            return BaseResponse.ok();
        } catch (SystemException systemException) {
            return BaseResponse.fail(INTERNAL_SERVER_ERROR, systemException.getMsg());
        } catch (Exception e) {
            return BaseResponse.fail(ERROR, e.getMessage());
        }
    }
}
